<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Raffle_model extends CI_Model {
    
    public function __construct()
    {
        parent::__construct();
    }
    
    // ------------------------------------------------------------------------
    
    public function create_key()
    {
        $this->load->helper('string');
        
        $fields['key']      = random_string('alnum', 10);
        $fields['created']  = date('Y-m-d H:i:s');
        $fields['user_id']  = $this->session->userdata('user_id');
        
        $this->db->insert('raffle', $fields);
        
        return $this->db->affected_rows() > 0 ? $fields['key'] : FALSE;
    }
    
    // ------------------------------------------------------------------------
    
    public function get_current_draw()
    {
        $query = $this->db->where('past_draw', 'n')
                          ->where('deleted', 'n')
                          ->get('draws', 1);
                          
        return $query->num_rows() > 0 ? $query->row_array() : FALSE;
    }
    
    // ------------------------------------------------------------------------
    
    public function get_raffle_code($where = '')
    {
        if (! is_array($where)) return FALSE;
        
        $query = $this->db->where($where)
                          ->where('deleted', 'n')
                          ->get('raffle', 1);
                          
        return $query->num_rows() > 0 ? $query->row_array() : FALSE;
    }
    
    // ------------------------------------------------------------------------
    
    public function draw_raffle_code()
    {
        // get randome query from diwa tips
    }
    
    // ------------------------------------------------------------------------
    
}

/* End of file raffle_model.php */
/* Location: ./application/models/raffle_model.php */